package com.wf.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mpk
 * @since 2024/10/16 10:52:36
 */
@Configuration
public class LoanMessageConfig {

    public static final String LOAN_TARGET_EXCHANGE = "loan_target_exchange";

    public static final String LOAN_TARGET_QUEUE = "loan_target_queue";

    public static final String LOAN_TARGET_ROUTING_KEY = "loan_target_routing_key";

    public static final String LOAN_TARGET_DEAD_LETTER_EXCHANGE = "loan_target_dead_letter_exchange";

    public static final String LOAN_TARGET_DEAD_LETTER_QUEUE = "loan_target_dead_letter_queue";

    public static final String LOAN_TARGET_DEAD_LETTER_ROUTING_KEY = "loan_target_dead_letter_routing_key";
    //声明交换机
    @Bean
    public DirectExchange confirmExchange() {
        return new DirectExchange(LOAN_TARGET_EXCHANGE);
    }

    //声明队列
    @Bean
    public Queue confirmQueue() {
        return QueueBuilder.durable(LOAN_TARGET_QUEUE).build();
    }

    //声明队列confirm_queue绑定关系 routingKey
    @Bean
    public Binding queueBinding(
            @Qualifier("confirmQueue") Queue queue,
            @Qualifier("confirmExchange") DirectExchange exchange
    ) {
        return BindingBuilder.bind(queue).to(exchange).with(LOAN_TARGET_ROUTING_KEY);
    }





}
